package mmc.objects;

import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glTexCoord2f;
import mmc.Constants;
import mmc.EngineObject;
import mmc.resource.Texture;
import mmc.resource.TextureLoader;

import org.lwjgl.opengl.GL11;


@SuppressWarnings("serial")
public class Mark extends EngineObject{
	static  Texture tex;
	
	static{
		if(!Constants.IS_SERVER){
			tex = TextureLoader.load("mmc/resource/data/Mark.png");
		}
	}
	
	
	private transient float rotateup = 0.0f;
    private transient float rotate = 0.0f;
    
    
	public Mark(float x, float y, float z) {
		super(x, y, z);
		health=1e-9f;
	}

	@Override
	public void render(EngineObject observer) {
		//System.out.println(x + " " + y + " " + z);
		
		glPushMatrix();
		//GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        //GL11.glLoadIdentity();
        GL11.glTranslatef(x, y+1.0f+ 0.5f*Math.abs((float)Math.sin(Math.toDegrees(rotateup))), z);
        GL11.glScalef(0.2f, 0.2f, 0.2f);
        GL11.glRotatef(rotate, 0.0f, 1.0f, 0.0f);
      //  CellArray.blockTexture.bind();
       
        tex.bind();
        
        //GL11.glColor3f(1.0f, 0.0f, 0.0f);
        GL11.glBegin(GL11.GL_TRIANGLES);

        
        	glTexCoord2f(0, 0);
        	GL11.glVertex3f(-0.5f, 0.0f, 0.5f);            
        	glTexCoord2f(1, 0);
        	GL11.glVertex3f( 0.5f, 0.0f, 0.5f);
           	glTexCoord2f(1, 1);
        	GL11.glVertex3f( 0.0f, -1.0f, 0.0f);
        
        	GL11.glNormal3f(0.0f, 0.0f, -1.0f); // Normal Pointing Away From Viewer
        	glTexCoord2f(0, 0);
            GL11.glVertex3f(-0.5f, 0.0f, -0.5f);            
            glTexCoord2f(1, 0);
            GL11.glVertex3f( 0.5f, 0.0f, -0.5f);
            glTexCoord2f(1, 1);
            GL11.glVertex3f( 0.0f, -1.0f, 0.0f);

            GL11.glNormal3f(1.0f, 0.0f, 0.0f); // Normal Pointing Right
            
            glTexCoord2f(0, 0);
            GL11.glVertex3f(0.5f, 0.0f, -0.5f);            
            glTexCoord2f(1, 0);
            GL11.glVertex3f( 0.5f, 0.0f, 0.5f);
            glTexCoord2f(1, 1);
            GL11.glVertex3f( 0.0f, -1.0f, 0.0f);

            GL11.glNormal3f(-1.0f, 0.0f, 0.0f);
            
            glTexCoord2f(0, 0);
            GL11.glVertex3f(-0.5f, 0.0f, -0.5f);            
            glTexCoord2f(1, 0);
            GL11.glVertex3f( -0.5f, 0.0f, 0.5f);
            glTexCoord2f(1, 1);
            GL11.glVertex3f( 0.0f, -1.0f, 0.0f);
            
            GL11.glNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up
            glTexCoord2f(0, 0);
            GL11.glVertex3f(-0.5f, 0.0f, -0.5f);            
            glTexCoord2f(1, 0);
            GL11.glVertex3f( -0.5f, 0.0f, 0.5f);
            glTexCoord2f(1, 1);
            GL11.glVertex3f( 0.0f, -1.0f, 0.0f);
            
//--------
            
        	glTexCoord2f(0, 0);
        	GL11.glVertex3f(-0.5f, 0.0f, 0.5f);            
        	glTexCoord2f(1, 0);
        	GL11.glVertex3f( 0.5f, 0.0f, 0.5f);
           	glTexCoord2f(1, 1);
        	GL11.glVertex3f( 0.0f, 1.0f, 0.0f);
        
        	GL11.glNormal3f(0.0f, 0.0f, -1.0f); // Normal Pointing Away From Viewer
        	glTexCoord2f(0, 0);
            GL11.glVertex3f(-0.5f, 0.0f, -0.5f);            
            glTexCoord2f(1, 0);
            GL11.glVertex3f( 0.5f, 0.0f, -0.5f);
            glTexCoord2f(1, 1);
            GL11.glVertex3f( 0.0f, 1.0f, 0.0f);

            GL11.glNormal3f(1.0f, 0.0f, 0.0f); // Normal Pointing Right
            
            glTexCoord2f(0, 0);
            GL11.glVertex3f(0.5f, 0.0f, -0.5f);            
            glTexCoord2f(1, 0);
            GL11.glVertex3f( 0.5f, 0.0f, 0.5f);
            glTexCoord2f(1, 1);
            GL11.glVertex3f( 0.0f, 1.0f, 0.0f);

            GL11.glNormal3f(-1.0f, 0.0f, 0.0f);
            
            glTexCoord2f(0, 0);
            GL11.glVertex3f(-0.5f, 0.0f, -0.5f);            
            glTexCoord2f(1, 0);
            GL11.glVertex3f( -0.5f, 0.0f, 0.5f);
            glTexCoord2f(1, 1);
            GL11.glVertex3f( 0.0f, 1.0f, 0.0f);
            
            GL11.glNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up
            glTexCoord2f(0, 0);
            GL11.glVertex3f(-0.5f, 0.0f, -0.5f);            
            glTexCoord2f(1, 0);
            GL11.glVertex3f( -0.5f, 0.0f, 0.5f);
            glTexCoord2f(1, 1);
            GL11.glVertex3f( 0.0f, 1.0f, 0.0f);
            
        GL11.glEnd();
        
        glPopMatrix();
        
        rotateup += 0.00001f;
        rotate += 0.1f;
	}

	@Override
	public void update(float dt) {
		// TODO Auto-generated method stub
		
	}

}
